import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// ElementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/css/Global.css'


Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.prototype.$uploadUrl = "http://localhost:8888/upload"
// 当前的域名
Vue.prototype.$host = "http://" + window.location.host  + ":8888/images"


router.beforeEach((to, from, next) => {
    window.document.title = to.meta.title === undefined ? '毕业论文管理系统' : to.meta.title + "-毕业论文管理系统"
    let token = localStorage.getItem("token")
    let roles = localStorage.getItem("roles")
    if (token) {
        if (to.path === '/login') {
            if (roles === "student") next('/student/select_topic')
            else if (roles === "teacher") next('/teacher/publish_topic')
            else next('/admin/index')
        } else {
            next()
        }
    } else {
        if (to.path === '/login') {
            next()
        } else {
            next('/login')
        }
    }
})


new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
